package sdau.hjk.service.Impl;

import sdau.hjk.dao.IUserRecordDao;
import sdau.hjk.entity.UserRecord;
import sdau.hjk.service.IUserRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 *@version 1.0
 *@author: huangjiakai
 *@create:2021−02-16 10:19
 *@className:com.hjk.service.Impl.UserRecordService
 *@description: TODO
 */
@Service("userRecordService")
public class UserRecordService implements IUserRecordService {
    @Autowired
    private IUserRecordDao userRecordDao;

    @Override
    public List<UserRecord> findByMajorDate(String major, Date date) {
        return null;
    }

    @Override
    public List<UserRecord> findById(Integer id) {
        return userRecordDao.findById(id);
    }

    //保存打卡记录
    @Override
    public void saveUserRecord(UserRecord userRecord) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Date date =calendar.getTime();
        String dateStringParse = sdf.format(date);
        Date dateParse = sdf.parse(dateStringParse);
        userRecord.setDate(dateParse);
        userRecordDao.saveUserRecord(userRecord);
    }
}
